﻿namespace ExamV5.ManagSys
{
    using ExamV5;
    using System;
    using System.Configuration;
    using System.Data;
    using System.Data.SqlClient;
    using System.Web;
    using System.Web.Security;
    using System.Web.UI;
    using System.Web.UI.HtmlControls;
    using System.Web.UI.WebControls;

    public class FrmEditUserInfo : Page
    {
        protected Button butClose;
        protected Button butDefault;
        protected Button butHaveUser;
        protected DropDownList DDLDept;
        protected DropDownList DDLEdu;
        protected DropDownList DDLGWLevel;
        protected DropDownList DDLGWName;
        protected DropDownList DDLLevel;
        protected DropDownList DDLUPDept;
        protected DropDownList DDLUserSex;
        protected DropDownList DDLWorker;
        protected HtmlForm form1;
        protected HtmlHead Head1;
        private HttpCookie httpCookie_0 = null;
        private HttpCookie httpCookie_1 = null;
        private HttpCookie httpCookie_2 = null;
        private HttpCookie httpCookie_3 = null;
        protected Image ImageUser;
        private int int_0 = 0;
        private PublicFun publicFun_0 = new PublicFun();
        protected TextBox txtBrithday;
        protected TextBox txtJoinDate;
        protected TextBox txtLoginIP;
        protected TextBox txtMoveTel;
        protected TextBox txtReUserPwd;
        protected TextBox txtUserCode;
        protected TextBox txtUserName;
        protected TextBox txtUserPwd;
        protected TextBox txtUserSFZH;
        protected HtmlInputFile UpUserPhoto;

        protected void butDefault_Click(object sender, EventArgs e)
        {
            string str = "";
            string str2 = "";
            if ((this.int_0 == 0) && (this.publicFun_0.GetValues("select UserCode from UserInfo where UserCode='" + this.publicFun_0.CheckString(this.txtUserCode.Text) + "'", "UserCode").Trim() != ""))
            {
                base.Response.Write("<script>alert('〖" + this.txtUserCode.Text.Trim() + "〗帐号已经存在,无法注册！')</script>");
            }
            else if ((this.txtMoveTel.Text.Trim() != "") && (this.publicFun_0.GetValues("select UserCode from UserInfo where UserCode<>'" + this.txtUserCode.Text + "' and HandCombNO='" + this.publicFun_0.CheckString(this.txtMoveTel.Text) + "'", "UserCode").Trim() != ""))
            {
                base.Response.Write("<script>alert('〖" + this.txtMoveTel.Text.Trim() + "〗手机号码已经存在,无法注册！')</script>");
            }
            else if ((this.txtUserSFZH.Text.Trim() != "") && (this.publicFun_0.GetValues("select UserCode from UserInfo where  UserCode<>'" + this.txtUserCode.Text + "' and UserSFZH='" + this.publicFun_0.CheckString(this.txtUserSFZH.Text) + "'", "UserCode").Trim() != ""))
            {
                base.Response.Write("<script>alert('〖" + this.txtUserSFZH.Text.Trim() + "〗身份证号已经存在,无法注册！')</script>");
            }
            else
            {
                string strUserCode = this.publicFun_0.CheckString(this.txtUserCode.Text);
                if (strUserCode == "")
                {
                    base.Response.Write("<script>alert('用户帐号不可以为空,无法注册！')</script>");
                }
                else
                {
                    string str8 = this.publicFun_0.CheckString(this.txtUserName.Text);
                    string str6 = "";
                    string str5 = this.DDLLevel.SelectedItem.Value;
                    if (this.txtUserPwd.Text.Trim() != "")
                    {
                        str6 = FormsAuthentication.HashPasswordForStoringInConfigFile(this.txtUserPwd.Text.Trim(), "MD5").Trim();
                        if (str6.Length > 20)
                        {
                            str6 = str6.Substring(0, 20);
                        }
                    }
                    string fileName = this.UpUserPhoto.PostedFile.FileName;
                    if (fileName.Trim() != "")
                    {
                        string str20 = fileName.Substring(fileName.Length - 4);
                        str = ".JPG.GIF";
                        if (str.IndexOf(str20.ToUpper()) >= 0)
                        {
                            if (fileName.IndexOf(@"\", 0) > 0)
                            {
                                int num2 = fileName.LastIndexOf(@"\");
                                fileName = fileName.Substring(num2 + 1);
                                fileName = strUserCode + str20;
                            }
                            this.UpUserPhoto.PostedFile.SaveAs(base.Server.MapPath("../PublicFile/") + strUserCode + fileName);
                            fileName = strUserCode + fileName;
                        }
                        else
                        {
                            base.Response.Write("<script>alert('照片格式不正确！请上传jpg或gif图片文件')</script>");
                            return;
                        }
                    }
                    string str9 = this.DDLUserSex.SelectedItem.Text.Trim();
                    string str10 = this.DDLDept.SelectedItem.Value;
                    string text = this.DDLWorker.SelectedItem.Text;
                    string str14 = this.txtBrithday.Text.Trim();
                    string str19 = this.DDLEdu.SelectedItem.Value.Trim();
                    string str18 = this.publicFun_0.CheckString(this.txtUserSFZH.Text.Trim());
                    string str15 = this.txtJoinDate.Text.Trim();
                    string str13 = this.txtMoveTel.Text.Trim();
                    string str16 = this.DDLGWName.SelectedItem.Value.Trim();
                    string str17 = this.DDLGWLevel.SelectedItem.Value.Trim();
                    string str7 = this.txtLoginIP.Text.Trim();
                    if (str7.Trim() != "")
                    {
                        string[] strArray2 = str7.Split(new char[] { '.' });
                        if (strArray2.Length != 4)
                        {
                            base.Response.Write("<script>alert('指定登录IP地址不合法！')</script>");
                            return;
                        }
                        for (int i = 0; i < strArray2.Length; i++)
                        {
                            if (!((int.Parse(strArray2[i]) >= 0) ? (int.Parse(strArray2[i]) <= 0xff) : false))
                            {
                                base.Response.Write("<script>alert('指定登录IP地址不合法！')</script>");
                                return;
                            }
                        }
                    }
                    string str12 = "A";
                    if (this.int_0 != 0)
                    {
                        str2 = "update UserInfo set LoginIP='" + str7 + "',UserName='" + str8 + "',UserSex='" + str9 + "',DeptID='" + str10 + "',Worker='" + text + "',UserLevel='" + str5 + "',Flag='" + str12 + "',HandCombNO='" + str13 + "',UserAge='" + str14 + "',JoinWorkDate='" + str15 + "',UserGWName='" + str16 + "',UserGWLevel='" + str17 + "',UserSFZH='" + str18 + "',UserEdu='" + str19 + "',UserMemo=''";
                        if (str6.Trim() != "")
                        {
                            str2 = str2 + ",UserPwd='" + str6 + "'";
                        }
                        if (fileName.Trim() != "")
                        {
                            str2 = str2 + ",UserPhoto='" + fileName + "'";
                        }
                        str2 = str2 + " where ID=" + this.int_0;
                        if (str5 != "A")
                        {
                            str2 = str2 + ";update UserPower set AddNews='Y',AddForum='Y',AddPoll='Y',AddRubric='Y',AddSubject='Y',AddText='Y',AddPaper='Y',ManagUser='Y',ManagExam='N',AddLession='Y',AddStudyPlan='Y',AddExam='Y'  where UserCode='" + strUserCode + "' ";
                        }
                        else
                        {
                            str2 = str2 + ";delete UserPower  where UserCode='" + strUserCode + "' ;insert into UserPower(UserCode) values('" + strUserCode + "')";
                        }
                    }
                    else
                    {
                        str2 = "Insert into UserInfo(LoginIP,UserCode,UserName,UserSex,UserPwd,DeptID,Worker,UserPhoto,UserLevel,Flag,StyleInfo,HandCombNO,RacingFen,HandMemo,HandImg,UserAge,JoinWorkDate,UserGWName,UserGWLevel,UserSFZH,UserEdu,UserMemo,UserFen,UserMember) values(";
                        str2 = str2 + "'" + str7 + "','" + strUserCode + "','" + str8 + "','" + str9 + "','" + str6 + "','" + str10 + "','" + text + "','" + fileName + "','" + str5 + "','" + str12 + "','N','" + str13 + "','-1','','','" + str14 + "','" + str15 + "','" + str16 + "','" + str17 + "','" + str18 + "','" + str19 + "','','0','1')";
                        if (str5 == "A")
                        {
                            str2 = str2 + ";insert into UserPower(UserCode) values('" + strUserCode + "')";
                        }
                        else
                        {
                            str2 = str2 + ";insert into UserPower(UserCode,ManagPower,AddNews,AddForum,AddPoll,AddRubric,AddSubject,AddText,AddPaper,ManagUser,ManagExam,AddLession,AddStudyPlan,AddExam) values('" + strUserCode + "','N','Y','Y','Y','Y','Y','Y','Y','Y','N','Y','Y','Y')";
                        }
                    }
                    this.publicFun_0.ExecuteSql(str2 + ";insert into SysLogInfo(LogDisp,EditUser,EditUserCode) values('编辑[" + strUserCode + "]用户信息！','" + this.httpCookie_1.Value + "','" + this.httpCookie_0.Value + "')");
                    if (this.int_0 != 0)
                    {
                        base.Response.Write("<script>alert('编辑用户信息操作成功！');</script>");
                        base.Response.Write("<script>window.close();</script>");
                    }
                    else
                    {
                        this.publicFun_0.AddUserPaper(strUserCode);
                        this.method_1(strUserCode);
                        this.publicFun_0.AddUserWorkPaper(strUserCode);
                        base.Response.Write("<script>alert('编辑用户信息操作成功！');</script>");
                        base.Response.Write("<script>window.opener.location.href='ManagUserList.aspx';window.close();</script>");
                    }
                }
            }
        }

        protected void butHaveUser_Click(object sender, EventArgs e)
        {
            if (!(this.publicFun_0.GetValues("select UserCode from UserInfo where UserCode='" + this.publicFun_0.CheckString(this.txtUserCode.Text.Trim()) + "'", "UserCode") != ""))
            {
                base.Response.Write("<script>alert('恭喜〖" + this.txtUserCode.Text.Trim() + "〗帐号可以新增！')</script>");
            }
            else
            {
                base.Response.Write("<script>alert('〖" + this.txtUserCode.Text.Trim() + "〗帐号已经存在,无法新增！')</script>");
            }
        }

        protected void DDLUPDept_SelectedIndexChanged(object sender, EventArgs e)
        {
            this.DDLDept.Items.Clear();
            this.publicFun_0.LoadDeptInfo(this.DDLDept, this.DDLUPDept.SelectedItem.Value, this.httpCookie_0.Value, "B");
            if (this.DDLDept.Items.Count == 0)
            {
                if (!(this.DDLUPDept.SelectedItem.Value == "0"))
                {
                    ListItem item = new ListItem(this.DDLUPDept.SelectedItem.Text, this.DDLUPDept.SelectedItem.Value);
                    this.DDLDept.Items.Add(item);
                }
                else
                {
                    ListItem item2 = new ListItem("--所有部门--", "0");
                    this.DDLDept.Items.Insert(0, item2);
                }
            }
        }

        private void method_0()
        {
            try
            {
                SqlConnection connection = new SqlConnection(ConfigurationManager.ConnectionStrings["Conn"].ConnectionString);
                SqlCommand command = new SqlCommand("select * from UserInfo where ID=" + this.int_0, connection);
                connection.Open();
                SqlDataReader reader = command.ExecuteReader(CommandBehavior.CloseConnection);
                if (reader.Read())
                {
                    if (!(((this.httpCookie_2.Value != "B") || (reader["UserLevel"].ToString() != "C")) && ((this.httpCookie_2.Value == "A") ? (!(reader["UserLevel"].ToString() == "C") ? !(reader["UserLevel"].ToString() == "B") : false) : true)))
                    {
                        base.Response.Write("<script>alert('您非法操作了！')</script>");
                        this.butDefault.Visible = false;
                        return;
                    }
                    this.butDefault.Visible = true;
                    this.txtUserCode.Enabled = false;
                    this.txtUserCode.Text = reader["UserCode"].ToString();
                    this.txtUserName.Text = reader["UserName"].ToString();
                    this.DDLUserSex.SelectedIndex = -1;
                    this.DDLGWName.SelectedIndex = -1;
                    this.DDLDept.SelectedIndex = -1;
                    this.DDLGWLevel.SelectedIndex = -1;
                    this.DDLWorker.SelectedIndex = -1;
                    this.DDLEdu.SelectedIndex = -1;
                    this.DDLLevel.SelectedIndex = -1;
                    this.DDLWorker.Items.FindByText(reader["Worker"].ToString()).Selected = true;
                    this.DDLLevel.Items.FindByValue(reader["UserLevel"].ToString()).Selected = true;
                    this.publicFun_0.LoadDeptInfo(this.DDLDept, this.httpCookie_3.Value, this.httpCookie_0.Value, this.httpCookie_2.Value);
                    this.DDLDept.Items.FindByValue(reader["DeptID"].ToString()).Selected = true;
                    if (!(reader["UserPhoto"].ToString().Trim() == ""))
                    {
                        this.ImageUser.ImageUrl = "../publicFile/" + reader["UserPhoto"].ToString();
                    }
                    else
                    {
                        this.ImageUser.ImageUrl = "../publicFile/SysUserImg.gif";
                    }
                    this.txtMoveTel.Text = reader["HandCombNO"].ToString();
                    this.txtBrithday.Text = reader["UserAge"].ToString();
                    this.txtJoinDate.Text = reader["JoinWorkDate"].ToString();
                    this.txtUserSFZH.Text = reader["UserSFZH"].ToString();
                    this.txtLoginIP.Text = reader["LoginIP"].ToString();
                    this.DDLUserSex.Items.FindByValue(reader["UserSex"].ToString()).Selected = true;
                    this.DDLGWName.Items.FindByValue(reader["UserGWName"].ToString()).Selected = true;
                    this.DDLGWLevel.Items.FindByValue(reader["UserGWLevel"].ToString()).Selected = true;
                    this.DDLEdu.Items.FindByValue(reader["UserEdu"].ToString()).Selected = true;
                }
                reader.Close();
                reader.Close();
                command.Dispose();
                connection.Close();
                connection.Dispose();
            }
            catch
            {
            }
        }

        private void method_1(string string_0)
        {
            string str = "";
            string str2 = "";
            string str3 = "";
            string str4 = "";
            string str5 = "";
            SqlConnection connection = new SqlConnection(ConfigurationManager.ConnectionStrings["Conn"].ConnectionString);
            connection.Open();
            SqlCommand command = new SqlCommand("select ExamName,PaperStatus,RubricDist,SubjectID,SubjectName,PaperDiff,ExamTime,ID,PaperStatus,LastWorkName from PaperInfo where Convert(datetime,PaperEndTime)>getdate() and LastJoin='Y'", connection);
            SqlDataReader reader = command.ExecuteReader(CommandBehavior.CloseConnection);
            while (reader.Read())
            {
                int num;
                string[] strArray;
                string str7;
                string str8;
                string str9;
                str = reader["RubricDist"].ToString();
                str2 = reader["SubjectID"].ToString();
                reader["SubjectName"].ToString();
                str3 = reader["PaperDiff"].ToString();
                str4 = reader["PaperStatus"].ToString();
                reader["ExamName"].ToString();
                str5 = reader["ExamTime"].ToString();
                if (reader["LastWorkName"].ToString().Replace("##", "").Trim() != "")
                {
                    string values = this.publicFun_0.GetValues("select Worker from UserInfo where UserCode='" + string_0 + "'", "Worker");
                    if ((reader["LastWorkName"].ToString().IndexOf("#" + values + "#") != -1) && (this.publicFun_0.GetValues("select PaperID from ExamUser where  Flag='A' and  UserCode='" + string_0 + "' and PaperID=" + reader["ID"].ToString(), "PaperID") != ""))
                    {
                        strArray = str2.Split(new char[] { ',' });
                        str9 = "";
                        num = 0;
                        while (num < strArray.Length)
                        {
                            if (str9.Trim().Length != 0)
                            {
                                str9 = str9 + " or SubjectID='" + strArray[num].Trim() + "'";
                            }
                            else
                            {
                                str9 = "SubjectID='" + strArray[num].Trim() + "'";
                            }
                            num++;
                        }
                        try
                        {
                            str7 = "";
                            if (!(this.publicFun_0.GetValues("select PaperID from PaperRule where PaperID=" + reader["ID"].ToString(), "PaperID") != ""))
                            {
                                str7 = "A";
                            }
                            else
                            {
                                str7 = "B";
                            }
                            if (str7.Trim() == "A")
                            {
                                this.method_2(string_0, reader["ID"].ToString(), str.Trim(), str9, str3, str4, str5);
                            }
                            if (str7.Trim() == "B")
                            {
                                str8 = "select ID from RubricInfo where IsDel='N' and Flag='" + str4 + "' and ISCheck='N'";
                                this.method_3(string_0, reader["ID"].ToString(), str8, str, str5);
                            }
                        }
                        catch
                        {
                        }
                    }
                }
                else if (this.publicFun_0.GetValues("select PaperID from ExamUser where Flag='A' and  UserCode='" + string_0 + "' and PaperID=" + reader["ID"].ToString(), "PaperID") != "")
                {
                    strArray = str2.Split(new char[] { ',' });
                    str9 = "";
                    for (num = 0; num < strArray.Length; num++)
                    {
                        if (str9.Trim().Length != 0)
                        {
                            str9 = str9 + " or SubjectID='" + strArray[num].Trim() + "'";
                        }
                        else
                        {
                            str9 = "SubjectID='" + strArray[num].Trim() + "'";
                        }
                    }
                    try
                    {
                        str7 = "";
                        if (!(this.publicFun_0.GetValues("select PaperID from PaperRule where PaperID=" + reader["ID"].ToString(), "PaperID") != ""))
                        {
                            str7 = "A";
                        }
                        else
                        {
                            str7 = "B";
                        }
                        if (str7.Trim() == "A")
                        {
                            this.method_2(string_0, reader["ID"].ToString(), str.Trim(), str9, str3, str4, str5);
                        }
                        if (str7.Trim() == "B")
                        {
                            str8 = "select ID from RubricInfo where IsDel='N' and Flag='" + str4 + "' and ISCheck='N'";
                            this.method_3(string_0, reader["ID"].ToString(), str8, str, str5);
                        }
                        continue;
                    }
                    catch
                    {
                        continue;
                    }
                }
            }
            reader.Close();
            command.Dispose();
            connection.Close();
            connection.Dispose();
        }

        private void method_2(string string_0, string string_1, string string_2, string string_3, string string_4, string string_5, string string_6)
        {
            string str = "#";
            string str2 = "#";
            string str3 = "#";
            string str4 = "#";
            string str5 = "#";
            string str6 = "#";
            string str7 = "#";
            string str8 = "#";
            string str9 = "#";
            Random random = new Random();
            bool flag = true;
            string[] strArray = string_2.Split(new char[] { '#' });
            string str10 = string_5;
            string strSql = "select ID from RubricInfo where IsDel='N' and Flag='" + str10 + "' and ISCheck='N' and (" + string_3 + ")";
            SqlConnection selectConnection = new SqlConnection(ConfigurationManager.ConnectionStrings["Conn"].ConnectionString);
            DataSet dataSet = new DataSet();
            if (Convert.ToInt32(strArray[0]) > 0)
            {
                int num25 = Convert.ToInt32(strArray[0]);
                SqlDataAdapter adapter9 = new SqlDataAdapter(strSql + " and RubricType='A'", selectConnection);
                adapter9.Fill(dataSet, "AExamData");
                int count = dataSet.Tables["AExamData"].Rows.Count;
                while (flag)
                {
                    if (num25 == 0)
                    {
                        break;
                    }
                    int num27 = random.Next(count);
                    string str30 = dataSet.Tables["AExamData"].Rows[num27]["ID"].ToString() + "#";
                    if (str.IndexOf("#" + str30, 0) == -1)
                    {
                        str = str + str30;
                        num25--;
                    }
                }
                dataSet.Tables.Clear();
                adapter9.Dispose();
            }
            if (Convert.ToInt32(strArray[1]) > 0)
            {
                int num22 = Convert.ToInt32(strArray[1]);
                SqlDataAdapter adapter8 = new SqlDataAdapter(strSql + " and RubricType='B'", selectConnection);
                adapter8.Fill(dataSet, "BExamData");
                int maxValue = dataSet.Tables["BExamData"].Rows.Count;
                while (flag)
                {
                    if (num22 == 0)
                    {
                        break;
                    }
                    int num24 = random.Next(maxValue);
                    string str28 = dataSet.Tables["BExamData"].Rows[num24]["ID"].ToString() + "#";
                    if (str2.IndexOf("#" + str28, 0) == -1)
                    {
                        str2 = str2 + str28;
                        num22--;
                    }
                }
                dataSet.Tables.Clear();
                adapter8.Dispose();
            }
            if (Convert.ToInt32(strArray[2]) > 0)
            {
                int num19 = Convert.ToInt32(strArray[2]);
                SqlDataAdapter adapter7 = new SqlDataAdapter(strSql + " and RubricType='C'", selectConnection);
                adapter7.Fill(dataSet, "CExamData");
                int num20 = dataSet.Tables["CExamData"].Rows.Count;
                while (flag)
                {
                    if (num19 == 0)
                    {
                        break;
                    }
                    int num21 = random.Next(num20);
                    string str26 = dataSet.Tables["CExamData"].Rows[num21]["ID"].ToString() + "#";
                    if (str3.IndexOf("#" + str26, 0) == -1)
                    {
                        str3 = str3 + str26;
                        num19--;
                    }
                }
                dataSet.Tables.Clear();
                adapter7.Dispose();
            }
            if (Convert.ToInt32(strArray[3]) > 0)
            {
                int num16 = Convert.ToInt32(strArray[3]);
                SqlDataAdapter adapter6 = new SqlDataAdapter(strSql + " and RubricType='D'", selectConnection);
                adapter6.Fill(dataSet, "DExamData");
                int num17 = dataSet.Tables["DExamData"].Rows.Count;
                while (flag)
                {
                    if (num16 == 0)
                    {
                        break;
                    }
                    int num18 = random.Next(num17);
                    string str24 = dataSet.Tables["DExamData"].Rows[num18]["ID"].ToString() + "#";
                    if (str4.IndexOf("#" + str24, 0) == -1)
                    {
                        str4 = str4 + str24;
                        num16--;
                    }
                }
                dataSet.Tables.Clear();
                adapter6.Dispose();
            }
            if (Convert.ToInt32(strArray[4]) > 0)
            {
                int num13 = Convert.ToInt32(strArray[4]);
                SqlDataAdapter adapter5 = new SqlDataAdapter(strSql + " and RubricType='E'", selectConnection);
                adapter5.Fill(dataSet, "EExamData");
                int num14 = dataSet.Tables["EExamData"].Rows.Count;
                while (flag)
                {
                    if (num13 == 0)
                    {
                        break;
                    }
                    int num15 = random.Next(num14);
                    string str22 = dataSet.Tables["EExamData"].Rows[num15]["ID"].ToString() + "#";
                    if (str5.IndexOf("#" + str22, 0) == -1)
                    {
                        str5 = str5 + str22;
                        num13--;
                    }
                }
                dataSet.Tables.Clear();
                adapter5.Dispose();
            }
            if (Convert.ToInt32(strArray[5]) > 0)
            {
                int num10 = Convert.ToInt32(strArray[5]);
                SqlDataAdapter adapter4 = new SqlDataAdapter(strSql + " and RubricType='F'", selectConnection);
                adapter4.Fill(dataSet, "FExamData");
                int num11 = dataSet.Tables["FExamData"].Rows.Count;
                while (flag)
                {
                    if (num10 == 0)
                    {
                        break;
                    }
                    int num12 = random.Next(num11);
                    string str20 = dataSet.Tables["FExamData"].Rows[num12]["ID"].ToString() + "#";
                    if (str6.IndexOf("#" + str20, 0) == -1)
                    {
                        str6 = str6 + str20;
                        num10--;
                    }
                }
                dataSet.Tables.Clear();
                adapter4.Dispose();
            }
            if (Convert.ToInt32(strArray[6]) > 0)
            {
                int num7 = Convert.ToInt32(strArray[6]);
                SqlDataAdapter adapter3 = new SqlDataAdapter(strSql + " and RubricType='G'", selectConnection);
                adapter3.Fill(dataSet, "GExamData");
                int num8 = dataSet.Tables["GExamData"].Rows.Count;
                while (flag)
                {
                    if (num7 == 0)
                    {
                        break;
                    }
                    int num9 = random.Next(num8);
                    string str18 = dataSet.Tables["GExamData"].Rows[num9]["ID"].ToString() + "#";
                    if (str7.IndexOf("#" + str18, 0) == -1)
                    {
                        str7 = str7 + str18;
                        num7--;
                    }
                }
                dataSet.Tables.Clear();
                adapter3.Dispose();
            }
            if (Convert.ToInt32(strArray[7]) > 0)
            {
                int num4 = Convert.ToInt32(strArray[7]);
                SqlDataAdapter adapter2 = new SqlDataAdapter(strSql + " and RubricType='H'", selectConnection);
                adapter2.Fill(dataSet, "HExamData");
                int num5 = dataSet.Tables["HExamData"].Rows.Count;
                while (flag)
                {
                    if (num4 == 0)
                    {
                        break;
                    }
                    int num6 = random.Next(num5);
                    string str16 = dataSet.Tables["HExamData"].Rows[num6]["ID"].ToString() + "#";
                    if (str8.IndexOf("#" + str16, 0) == -1)
                    {
                        str8 = str8 + str16;
                        num4--;
                    }
                }
                dataSet.Tables.Clear();
                adapter2.Dispose();
            }
            if (Convert.ToInt32(strArray[8]) > 0)
            {
                int num = Convert.ToInt32(strArray[8]);
                SqlDataAdapter adapter = new SqlDataAdapter(strSql + " and RubricType='I'", selectConnection);
                adapter.Fill(dataSet, "IExamData");
                int num2 = dataSet.Tables["IExamData"].Rows.Count;
                while (flag)
                {
                    if (num == 0)
                    {
                        break;
                    }
                    int num3 = random.Next(num2);
                    string str14 = dataSet.Tables["IExamData"].Rows[num3]["ID"].ToString() + "#";
                    if (str9.IndexOf("#" + str14, 0) == -1)
                    {
                        str9 = str9 + str14;
                        num--;
                    }
                }
                dataSet.Tables.Clear();
                adapter.Dispose();
            }
            dataSet.Clear();
            dataSet.Dispose();
            selectConnection.Dispose();
            string values = this.publicFun_0.GetValues("select top 1 RubricJ from PaperData where PaperID=" + string_1, "RubricJ");
            if (!(values != ""))
            {
                values = "";
            }
            else
            {
                values = values.Trim().Replace("_", "#");
            }
            if (str.Length <= 1)
            {
                str = "";
            }
            else
            {
                str = str.Substring(1);
            }
            if (str2.Length <= 1)
            {
                str2 = "";
            }
            else
            {
                str2 = str2.Substring(1);
            }
            if (str3.Length <= 1)
            {
                str3 = "";
            }
            else
            {
                str3 = str3.Substring(1);
            }
            if (str4.Length <= 1)
            {
                str4 = "";
            }
            else
            {
                str4 = str4.Substring(1);
            }
            if (str5.Length <= 1)
            {
                str5 = "";
            }
            else
            {
                str5 = str5.Substring(1);
            }
            if (str6.Length <= 1)
            {
                str6 = "";
            }
            else
            {
                str6 = str6.Substring(1);
            }
            if (str7.Length <= 1)
            {
                str7 = "";
            }
            else
            {
                str7 = str7.Substring(1);
            }
            if (str8.Length <= 1)
            {
                str8 = "";
            }
            else
            {
                str8 = str8.Substring(1);
            }
            if (str9.Length > 1)
            {
                str9 = str9.Substring(1);
            }
            else
            {
                str9 = "";
            }
            strSql = "update ExamUser set LastTime='" + string_6 + "',Flag='A',IsSave=0,StartTime='',EndTime='',GetOldCountFen=0,GetCountFen=0,LoginIP='' where UserCode='" + string_0 + "' and PaperID=" + string_1;
            strSql = strSql + ";update PaperData set RubricS='" + str + "',RubricD='" + str2 + "',RubricB='" + str3 + "',RubricF='" + str4 + "',RubricA='" + str5 + "',RubricC='" + str6 + "',RubricT='" + str7 + "',RubricAN='" + str8 + "',RubricO='" + str9 + "',RubricJ='" + values + "' where PaperID='" + string_1 + "' and UserCode='" + string_0 + "'";
            strSql = strSql + ";delete from CheckPaper where  UserCode='" + string_0 + "' and PaperID=" + string_1;
            this.publicFun_0.ExecuteSql(strSql);
        }

        private void method_3(string string_0, string string_1, string string_2, string string_3, string string_4)
        {
            SqlDataReader reader;
            SqlCommand command;
            SqlConnection connection2;
            string str14;
            int count;
            int num3;
            string str = "#";
            string str2 = "#";
            string str3 = "#";
            string str4 = "#";
            string str5 = "#";
            string str6 = "#";
            string str7 = "#";
            string str8 = "#";
            string str9 = "#";
            Random random = new Random();
            bool flag = true;
            string str10 = "";
            int num = 0;
            string[] strArray = string_3.Split(new char[] { '#' });
            string strSql = "";
            string connectionString = ConfigurationManager.ConnectionStrings["Conn"].ConnectionString;
            SqlConnection selectConnection = new SqlConnection(connectionString);
            DataSet dataSet = new DataSet();
            if (Convert.ToInt32(strArray[0]) > 0)
            {
                connection2 = new SqlConnection(connectionString);
                connection2.Open();
                command = new SqlCommand("select RuleValue,GetNum from PaperRule where PaperID=" + string_1 + " and RubricType='A'", connection2);
                reader = command.ExecuteReader(CommandBehavior.CloseConnection);
                SqlDataAdapter adapter9 = null;
                while (reader.Read())
                {
                    str10 = reader["RuleValue"].ToString().Trim().Replace('‘', '\'').Replace("’", "'");
                    num = Convert.ToInt32(reader["GetNum"].ToString().Trim());
                    adapter9 = new SqlDataAdapter(string_2 + "  and (" + str10 + ")", selectConnection);
                    adapter9.Fill(dataSet, "AExamData");
                    count = dataSet.Tables["AExamData"].Rows.Count;
                    while (flag)
                    {
                        if (num == 0)
                        {
                            break;
                        }
                        num3 = random.Next(count);
                        str14 = dataSet.Tables["AExamData"].Rows[num3]["ID"].ToString() + "#";
                        if (str.IndexOf("#" + str14, 0) == -1)
                        {
                            str = str + str14;
                            num--;
                        }
                    }
                    adapter9.Dispose();
                    dataSet.Tables.Clear();
                }
                reader.Close();
                command.Dispose();
                connection2.Close();
                connection2.Dispose();
            }
            if (Convert.ToInt32(strArray[1]) > 0)
            {
                connection2 = new SqlConnection(connectionString);
                connection2.Open();
                command = new SqlCommand("select RuleValue,GetNum from PaperRule where PaperID=" + string_1 + " and RubricType='B'", connection2);
                reader = command.ExecuteReader(CommandBehavior.CloseConnection);
                SqlDataAdapter adapter8 = null;
                while (reader.Read())
                {
                    str10 = reader["RuleValue"].ToString().Trim().Replace('‘', '\'').Replace("’", "'");
                    num = Convert.ToInt32(reader["GetNum"].ToString().Trim());
                    adapter8 = new SqlDataAdapter(string_2 + " and (" + str10 + ")", selectConnection);
                    adapter8.Fill(dataSet, "BExamData");
                    count = dataSet.Tables["BExamData"].Rows.Count;
                    while (flag)
                    {
                        if (num == 0)
                        {
                            break;
                        }
                        num3 = random.Next(count);
                        str14 = dataSet.Tables["BExamData"].Rows[num3]["ID"].ToString() + "#";
                        if (str2.IndexOf("#" + str14, 0) == -1)
                        {
                            str2 = str2 + str14;
                            num--;
                        }
                    }
                    adapter8.Dispose();
                    dataSet.Tables.Clear();
                }
                reader.Close();
                command.Dispose();
                connection2.Close();
                connection2.Dispose();
            }
            if (Convert.ToInt32(strArray[2]) > 0)
            {
                connection2 = new SqlConnection(connectionString);
                connection2.Open();
                command = new SqlCommand("select RuleValue,GetNum from PaperRule where PaperID=" + string_1 + " and RubricType='C'", connection2);
                reader = command.ExecuteReader(CommandBehavior.CloseConnection);
                SqlDataAdapter adapter7 = null;
                while (reader.Read())
                {
                    str10 = reader["RuleValue"].ToString().Trim().Replace('‘', '\'').Replace("’", "'");
                    num = Convert.ToInt32(reader["GetNum"].ToString().Trim());
                    adapter7 = new SqlDataAdapter(string_2 + " and (" + str10 + ")", selectConnection);
                    adapter7.Fill(dataSet, "CExamData");
                    count = dataSet.Tables["CExamData"].Rows.Count;
                    while (flag)
                    {
                        if (num == 0)
                        {
                            break;
                        }
                        num3 = random.Next(count);
                        str14 = dataSet.Tables["CExamData"].Rows[num3]["ID"].ToString() + "#";
                        if (str3.IndexOf("#" + str14, 0) == -1)
                        {
                            str3 = str3 + str14;
                            num--;
                        }
                    }
                    adapter7.Dispose();
                    dataSet.Tables.Clear();
                }
                reader.Close();
                command.Dispose();
                connection2.Close();
                connection2.Dispose();
            }
            if (Convert.ToInt32(strArray[3]) > 0)
            {
                connection2 = new SqlConnection(connectionString);
                connection2.Open();
                command = new SqlCommand("select RuleValue,GetNum from PaperRule where PaperID=" + string_1 + " and RubricType='D'", connection2);
                reader = command.ExecuteReader(CommandBehavior.CloseConnection);
                SqlDataAdapter adapter6 = null;
                while (reader.Read())
                {
                    str10 = reader["RuleValue"].ToString().Trim().Replace('‘', '\'').Replace("’", "'");
                    num = Convert.ToInt32(reader["GetNum"].ToString().Trim());
                    adapter6 = new SqlDataAdapter(string_2 + " and (" + str10 + ")", selectConnection);
                    adapter6.Fill(dataSet, "DExamData");
                    count = dataSet.Tables["DExamData"].Rows.Count;
                    while (flag)
                    {
                        if (num == 0)
                        {
                            break;
                        }
                        num3 = random.Next(count);
                        str14 = dataSet.Tables["DExamData"].Rows[num3]["ID"].ToString() + "#";
                        if (str4.IndexOf("#" + str14, 0) == -1)
                        {
                            str4 = str4 + str14;
                            num--;
                        }
                    }
                    adapter6.Dispose();
                    dataSet.Tables.Clear();
                }
                reader.Close();
                command.Dispose();
                connection2.Close();
                connection2.Dispose();
            }
            if (Convert.ToInt32(strArray[4]) > 0)
            {
                connection2 = new SqlConnection(connectionString);
                connection2.Open();
                command = new SqlCommand("select RuleValue,GetNum from PaperRule where PaperID=" + string_1 + " and RubricType='E'", connection2);
                reader = command.ExecuteReader(CommandBehavior.CloseConnection);
                SqlDataAdapter adapter5 = null;
                while (reader.Read())
                {
                    str10 = reader["RuleValue"].ToString().Trim().Replace('‘', '\'').Replace("’", "'");
                    num = Convert.ToInt32(reader["GetNum"].ToString().Trim());
                    adapter5 = new SqlDataAdapter(string_2 + " and (" + str10 + ")", selectConnection);
                    adapter5.Fill(dataSet, "EExamData");
                    count = dataSet.Tables["EExamData"].Rows.Count;
                    while (flag)
                    {
                        if (num == 0)
                        {
                            break;
                        }
                        num3 = random.Next(count);
                        str14 = dataSet.Tables["EExamData"].Rows[num3]["ID"].ToString() + "#";
                        if (str5.IndexOf("#" + str14, 0) == -1)
                        {
                            str5 = str5 + str14;
                            num--;
                        }
                    }
                    adapter5.Dispose();
                    dataSet.Tables.Clear();
                }
                reader.Close();
                command.Dispose();
                connection2.Close();
                connection2.Dispose();
            }
            if (Convert.ToInt32(strArray[5]) > 0)
            {
                connection2 = new SqlConnection(connectionString);
                connection2.Open();
                command = new SqlCommand("select RuleValue,GetNum from PaperRule where PaperID=" + string_1 + " and RubricType='F'", connection2);
                reader = command.ExecuteReader(CommandBehavior.CloseConnection);
                SqlDataAdapter adapter4 = null;
                while (reader.Read())
                {
                    str10 = reader["RuleValue"].ToString().Trim().Replace('‘', '\'').Replace("’", "'");
                    num = Convert.ToInt32(reader["GetNum"].ToString().Trim());
                    adapter4 = new SqlDataAdapter(string_2 + " and (" + str10 + ")", selectConnection);
                    adapter4.Fill(dataSet, "FExamData");
                    count = dataSet.Tables["FExamData"].Rows.Count;
                    while (flag)
                    {
                        if (num == 0)
                        {
                            break;
                        }
                        num3 = random.Next(count);
                        str14 = dataSet.Tables["FExamData"].Rows[num3]["ID"].ToString() + "#";
                        if (str6.IndexOf("#" + str14, 0) == -1)
                        {
                            str6 = str6 + str14;
                            num--;
                        }
                    }
                    adapter4.Dispose();
                    dataSet.Tables.Clear();
                }
                reader.Close();
                command.Dispose();
                connection2.Close();
                connection2.Dispose();
            }
            if (Convert.ToInt32(strArray[6]) > 0)
            {
                connection2 = new SqlConnection(connectionString);
                connection2.Open();
                command = new SqlCommand("select RuleValue,GetNum from PaperRule where PaperID=" + string_1 + " and RubricType='G'", connection2);
                reader = command.ExecuteReader(CommandBehavior.CloseConnection);
                SqlDataAdapter adapter3 = null;
                while (reader.Read())
                {
                    str10 = reader["RuleValue"].ToString().Trim().Replace('‘', '\'').Replace("’", "'");
                    num = Convert.ToInt32(reader["GetNum"].ToString().Trim());
                    adapter3 = new SqlDataAdapter(string_2 + " and (" + str10 + ")", selectConnection);
                    adapter3.Fill(dataSet, "GExamData");
                    count = dataSet.Tables["GExamData"].Rows.Count;
                    while (flag)
                    {
                        if (num == 0)
                        {
                            break;
                        }
                        num3 = random.Next(count);
                        str14 = dataSet.Tables["GExamData"].Rows[num3]["ID"].ToString() + "#";
                        if (str7.IndexOf("#" + str14, 0) == -1)
                        {
                            str7 = str7 + str14;
                            num--;
                        }
                    }
                    adapter3.Dispose();
                    dataSet.Tables.Clear();
                }
                reader.Close();
                command.Dispose();
                connection2.Close();
                connection2.Dispose();
            }
            if (Convert.ToInt32(strArray[7]) > 0)
            {
                connection2 = new SqlConnection(connectionString);
                connection2.Open();
                command = new SqlCommand("select RuleValue,GetNum from PaperRule where PaperID=" + string_1 + " and RubricType='H'", connection2);
                reader = command.ExecuteReader(CommandBehavior.CloseConnection);
                SqlDataAdapter adapter2 = null;
                while (reader.Read())
                {
                    str10 = reader["RuleValue"].ToString().Trim().Replace('‘', '\'').Replace("’", "'");
                    num = Convert.ToInt32(reader["GetNum"].ToString().Trim());
                    adapter2 = new SqlDataAdapter(string_2 + " and (" + str10 + ")", selectConnection);
                    adapter2.Fill(dataSet, "HExamData");
                    count = dataSet.Tables["HExamData"].Rows.Count;
                    while (flag)
                    {
                        if (num == 0)
                        {
                            break;
                        }
                        num3 = random.Next(count);
                        str14 = dataSet.Tables["HExamData"].Rows[num3]["ID"].ToString() + "#";
                        if (str8.IndexOf("#" + str14, 0) == -1)
                        {
                            str8 = str8 + str14;
                            num--;
                        }
                    }
                    adapter2.Dispose();
                    dataSet.Tables.Clear();
                }
                reader.Close();
                command.Dispose();
                connection2.Close();
                connection2.Dispose();
            }
            if (Convert.ToInt32(strArray[8]) > 0)
            {
                connection2 = new SqlConnection(connectionString);
                connection2.Open();
                command = new SqlCommand("select RuleValue,GetNum from PaperRule where PaperID=" + string_1 + " and RubricType='I'", connection2);
                reader = command.ExecuteReader(CommandBehavior.CloseConnection);
                SqlDataAdapter adapter = null;
                while (reader.Read())
                {
                    str10 = reader["RuleValue"].ToString().Trim().Replace('‘', '\'').Replace("’", "'");
                    num = Convert.ToInt32(reader["GetNum"].ToString().Trim());
                    adapter = new SqlDataAdapter(string_2 + " and (" + str10 + ")", selectConnection);
                    adapter.Fill(dataSet, "IExamData");
                    count = dataSet.Tables["IExamData"].Rows.Count;
                    while (flag)
                    {
                        if (num == 0)
                        {
                            break;
                        }
                        num3 = random.Next(count);
                        str14 = dataSet.Tables["IExamData"].Rows[num3]["ID"].ToString() + "#";
                        if (str9.IndexOf("#" + str14, 0) == -1)
                        {
                            str9 = str9 + str14;
                            num--;
                        }
                    }
                    adapter.Dispose();
                    dataSet.Tables.Clear();
                }
                reader.Close();
                command.Dispose();
                connection2.Close();
                connection2.Dispose();
            }
            dataSet.Clear();
            dataSet.Dispose();
            selectConnection.Close();
            selectConnection.Dispose();
            string values = this.publicFun_0.GetValues("select top 1 RubricJ from PaperData where PaperID=" + string_1, "RubricJ");
            if (values != "")
            {
                values = values.Trim().Replace("_", "#");
            }
            else
            {
                values = "";
            }
            if (str.Length > 1)
            {
                str = str.Substring(1);
            }
            else
            {
                str = "";
            }
            if (str2.Length <= 1)
            {
                str2 = "";
            }
            else
            {
                str2 = str2.Substring(1);
            }
            if (str3.Length <= 1)
            {
                str3 = "";
            }
            else
            {
                str3 = str3.Substring(1);
            }
            if (str4.Length <= 1)
            {
                str4 = "";
            }
            else
            {
                str4 = str4.Substring(1);
            }
            if (str5.Length <= 1)
            {
                str5 = "";
            }
            else
            {
                str5 = str5.Substring(1);
            }
            if (str6.Length > 1)
            {
                str6 = str6.Substring(1);
            }
            else
            {
                str6 = "";
            }
            if (str7.Length <= 1)
            {
                str7 = "";
            }
            else
            {
                str7 = str7.Substring(1);
            }
            if (str8.Length > 1)
            {
                str8 = str8.Substring(1);
            }
            else
            {
                str8 = "";
            }
            if (str9.Length <= 1)
            {
                str9 = "";
            }
            else
            {
                str9 = str9.Substring(1);
            }
            strSql = "update ExamUser set LastTime='" + string_4 + "',Flag='A',IsSave=0,StartTime='',EndTime='',GetOldCountFen=0,GetCountFen=0,LoginIP='' where UserCode='" + string_0 + "' and PaperID=" + string_1;
            strSql = strSql + ";update PaperData set RubricS='" + str + "',RubricD='" + str2 + "',RubricB='" + str3 + "',RubricF='" + str4 + "',RubricA='" + str5 + "',RubricC='" + str6 + "',RubricT='" + str7 + "',RubricAN='" + str8 + "',RubricO='" + str9 + "',RubricJ='" + values + "' where PaperID='" + string_1 + "' and UserCode='" + string_0 + "'";
            strSql = strSql + ";delete from CheckPaper where  UserCode='" + string_0 + "' and PaperID=" + string_1;
            this.publicFun_0.ExecuteSql(strSql);
        }

        protected void Page_Load(object sender, EventArgs e)
        {
            this.Page.Title = ConfigurationManager.ConnectionStrings["ProTitle"].ConnectionString;
            this.httpCookie_0 = new HttpCookie("ExamUserCode");
            this.httpCookie_0 = base.Request.Cookies["ExamUserCode"];
            this.httpCookie_1 = new HttpCookie("ExamUserName");
            this.httpCookie_1 = base.Request.Cookies["ExamUserName"];
            this.httpCookie_2 = new HttpCookie("ExamUserLevel");
            this.httpCookie_2 = base.Request.Cookies["ExamUserLevel"];
            this.httpCookie_3 = new HttpCookie("ExamDeptID");
            this.httpCookie_3 = base.Request.Cookies["ExamDeptID"];
            if ((this.httpCookie_0 != null) ? !(this.httpCookie_0.Value == "") : false)
            {
                base.Response.Cache.SetCacheability(HttpCacheability.NoCache);
                base.Response.Cache.SetNoStore();
                this.httpCookie_0.Value = this.publicFun_0.CheckString(base.Server.UrlDecode(this.httpCookie_0.Value));
                this.httpCookie_1.Value = this.publicFun_0.CheckString(base.Server.UrlDecode(this.httpCookie_1.Value));
                this.httpCookie_2.Value = this.publicFun_0.CheckString(base.Server.UrlDecode(this.httpCookie_2.Value));
                this.httpCookie_3.Value = this.publicFun_0.CheckString(base.Server.UrlDecode(this.httpCookie_3.Value));
                this.int_0 = Convert.ToInt32(base.Request["ID"]);
                if (!base.IsPostBack)
                {
                    base.Response.Cache.SetCacheability(HttpCacheability.NoCache);
                    base.Response.Cache.SetNoStore();
                    if (this.publicFun_0.ReturnPaperData() == "Yes")
                    {
                        ListItem item4;
                        if (this.httpCookie_2.Value == "C")
                        {
                            item4 = new ListItem("管理员", "C");
                            this.DDLLevel.Items.Add(item4);
                        }
                        this.DDLUPDept.DataTextField = "DeptName";
                        this.DDLUPDept.DataValueField = "ID";
                        if (this.httpCookie_2.Value == "C")
                        {
                            this.DDLUPDept.DataSource = this.publicFun_0.RetrunDataView("select ID,DeptName from DeptInfo where UPID=0  order by SortInfo,ID");
                        }
                        else
                        {
                            this.DDLUPDept.DataSource = this.publicFun_0.RetrunDataView("select ID,DeptName from DeptInfo where ID=" + this.httpCookie_3.Value + "  order by SortInfo,ID");
                        }
                        this.DDLUPDept.DataBind();
                        if (!(this.httpCookie_2.Value == "C"))
                        {
                            this.DDLDept.Items.Clear();
                            this.publicFun_0.LoadDeptInfo(this.DDLDept, this.DDLUPDept.SelectedItem.Value, this.httpCookie_0.Value, "B");
                            if (this.DDLDept.Items.Count == 0)
                            {
                                ListItem item3 = new ListItem(this.DDLUPDept.SelectedItem.Text, this.DDLUPDept.SelectedItem.Value);
                                this.DDLDept.Items.Add(item3);
                            }
                        }
                        else
                        {
                            this.DDLUPDept.SelectedIndex = -1;
                            this.DDLDept.SelectedIndex = -1;
                            item4 = new ListItem("--所有单位--", "0");
                            ListItem item5 = new ListItem("--所有部门--", "0");
                            this.DDLDept.Items.Insert(0, item5);
                            this.DDLUPDept.Items.Insert(0, item4);
                        }
                        this.DDLWorker.DataTextField = "ParmName";
                        this.DDLWorker.DataValueField = "ParmValue";
                        this.DDLWorker.DataSource = this.publicFun_0.RetrunDataView("select ParmName,ParmValue from SysParmInfo where ParmMemo='Worker'");
                        this.DDLWorker.DataBind();
                        ListItem item = new ListItem("--请选择--", "0");
                        this.DDLWorker.Items.Add(item);
                        this.DDLWorker.Items.FindByValue("0").Selected = true;
                        this.DDLGWName.DataTextField = "ParmName";
                        this.DDLGWName.DataValueField = "ParmValue";
                        this.DDLGWName.DataSource = this.publicFun_0.RetrunDataView("select ParmName,ParmValue from SysParmInfo where ParmMemo='GWName'");
                        this.DDLGWName.DataBind();
                        ListItem item2 = new ListItem("--请选择--", "");
                        this.DDLGWName.Items.Add(item2);
                        this.DDLGWName.Items.FindByValue("").Selected = true;
                        if (this.int_0 == 0)
                        {
                            this.txtUserCode.Enabled = true;
                        }
                        else
                        {
                            this.method_0();
                        }
                        if (this.publicFun_0.GetValues("select ManagUser from UserPower where UserCode='" + this.httpCookie_0.Value + "'", "ManagUser") != "Y")
                        {
                            this.butDefault.Visible = false;
                        }
                    }
                    else
                    {
                        base.Response.Write("<script>alert('此版本暂未授权,请拔打(0)13870606104手机号进行授权！')</script>");
                    }
                }
            }
            else
            {
                base.Response.Write("<script language=javascript>top.location.href='../Index.htm';self.close();</script>");
            }
        }
    }
}

